package com.myacg.core.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

public class PropertieUtils {
	private static PropertieUtils propertieUtils=new PropertieUtils();
	/**
	 * 配置文件加载器
	 * @param path
	 * @return
	 */
    public static Map<String, String> getProperties(String path){
	    return getProperties("", path);
    }
	/**
	 * 配置文件加载器
	 * @param path
	 * @return
	 */
    public static Map<String, String> getProperties(String pathPre,String path){
	    Properties pro=new Properties();
	    InputStream inputStream =propertieUtils.getClass().getClassLoader().getResourceAsStream(pathPre+path);
	    try {
			pro.load(inputStream); 
		} catch (IOException e) {
			System.err.println("配置文件加载异常："+path+"："+e.getMessage());
			return null;
		}
	    Map<String, String> map=new HashMap<String, String>(); 
		Set<Object> set =  pro.keySet();
		for (Object object : set) {
			 map.put((String) object, pro.getProperty((String)object));
		}
		System.out.println("--》配置文件加载成功："+path+"--------------");
		return map;
    }
}
